package com.huawei.crm.domain;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Data
@TableName("customertracehistory")
public class Customertracehistory extends BaseEntity {

    @TableId(type = IdType.AUTO)
    private Long id;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;

    private String traceDetails;

    private Systemdictionaryitem type;

    private Integer traceResult;

    private String remark;

    private Customer customer;

    private Employee inputUser;

    private Date inputTime;

    public String getTraceResultName() {
        String resultName = "";
        if (traceResult == 1) {
            resultName = "差";
        } else if (traceResult == 2) {
            resultName = "中";
        } else {
            resultName = "优";
        }
        return resultName;
    }

    public String getJson() {
        // Json默认将时间转换成毫秒值我们手动将日期转成字符串
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Map<String, Object> map = new HashMap<>();
        map.put("customerName", customer.getName());
        map.put("traceTime", sdf.format(traceTime));
        map.put("traceDetails", traceDetails);
        map.put("typeId", type.getId());
        map.put("traceResult", traceResult);
        map.put("remark", remark);
        map.put("id", id);
        return JSON.toJSONString(map);
    }
}